<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="900" destroy-on-close @closed="$emit('closed')">
		<el-card>
			<template #header>
				{{procedurePatch.procedure_name}} 
			</template>
			<el-row :gutter="21">
				<el-col :span="7">
					数量：{{procedurePatch.number}}
				</el-col>
				<el-col :span="7">
					{{procedurePatch.color}}
				</el-col>
				<el-col :span="7">
					{{procedurePatch.size}}
				</el-col>
			</el-row>
			<el-row :gutter="21">
				<el-col :span="7">
					缸号：{{procedurePatch.gh}}
				</el-col>
				<el-col :span="14">
					{{procedurePatch.created_at}}
				</el-col>
			</el-row>

		</el-card>
		<el-space wrap style="margin-top: 10px;">
			<div v-for="item in tasks" :key="item.id">
				<el-button v-if="item.is_do" type="success">{{item.process_name}}/{{item.staff_name}}</el-button>
				<el-button v-if="!item.is_do" type="danger" @click="staffCheck(item)">{{item.process_name}}</el-button>
			</div>
		</el-space>

		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

	<taskStaff-dialog v-if="dialog.taskStaff" ref="taskStaffDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></taskStaff-dialog>
</template>

<script>
	import taskStaffDialog from './taskStaff'
	import cloneDeep from 'lodash/cloneDeep'
	export default {
		emits: ['success', 'closed'],
		components: {
			taskStaffDialog
		},
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					show: '查看'
				},
				dialog: {
					taskStaff: false
				},
				visible: false,
				isSaveing: false,
				//表单数据
				
				procedurePatch: {}, 
				tasks: []
			}
		},
		mounted() {

		},
		methods: {
		
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			async getDetail() {

				var reqData = {
					id: this.procedurePatch.id
				}

				var res = await this.$API.procedure.getPatchDetail.get(reqData)

				if (res.code == 200) {
					this.tasks = res.data.patch_item.taskes
				}


			},
			staffCheck(item) {
				this.dialog.taskStaff = true
				this.$nextTick(() => {
					this.$refs.taskStaffDialog.open("show").setData(item)
				})
			},
			handleSaveSuccess() {
				this.getDetail()
			},
			//表单注入数据
			setData(data){

				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				this.procedurePatch = cloneDeep(data)
				this.getDetail()
			},
			
		}
	}
</script>

<style>
</style>
